//
//  YJBaseTableViewController.swift
//  YJWeiBo
//
//  Created by Jim1024 on 2017/1/13.
//  Copyright © 2017年 Jim1024. All rights reserved.
//

import UIKit

class YJBaseTableViewController: UITableViewController {
    
    /// 用户是否登录
    var userLogin = YJUserAccountViewModel.sharedInstance.userLogin
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    /// 设置访客视图
    private func setupVisitorView() {
        view = visitorView
        visitorView.delegate = self
        
        // 在这里根据不同的控制器类型来设置不同的访客视图内容
        // is: 判断对象是否是某个类型
        if self is YJHomeViewController {
            visitorView.startRotation()
        } else if self is YJMessageViewController {
            visitorView.setup(imageName: "visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        } else if self is YJDiscoverViewController {
            visitorView.setup(imageName: "visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        } else if self is YJProfileViewController {
            visitorView.setup(imageName: "visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.plain, target: self, action: #selector(YJVisitorViewDelegate.visitorViewDidClickRegisterButton))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.plain, target: self, action: #selector(YJVisitorViewDelegate.visitorViewDidClickLoginButton))
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    // MARK: - 懒加载
    fileprivate lazy var visitorView: YJVisitorView = YJVisitorView();

}

extension YJBaseTableViewController: YJVisitorViewDelegate {
    // 扩展里面不能放存储属性
    // var name: String?   ==> OC NSString *_name
    
    // 扩展里面可以存放计算性属性
    var name: String {
        get {
            return ""
        }
        
        set {
            
        }
    }
    
    func visitorViewDidClickRegisterButton() {
        JPrint(#function)
    }
    
    func visitorViewDidClickLoginButton() {
        // 弹出登录界面
        let oauthVC = YJOauthViewController()
        present(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
}
